package cn.iocoder.yudao.module.team.service.financemonad;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.team.controller.admin.financemonad.vo.*;
import cn.iocoder.yudao.module.team.dal.dataobject.financemonad.FinanceMonadDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.team.dal.mysql.financemonad.FinanceMonadMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.team.enums.ErrorCodeConstants.*;

/**
 * 录入单子管理 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class FinanceMonadServiceImpl implements FinanceMonadService {

    @Resource
    private FinanceMonadMapper financeMonadMapper;

    @Override
    public Integer createFinanceMonad(FinanceMonadSaveReqVO createReqVO) {
        // 插入
        FinanceMonadDO financeMonad = BeanUtils.toBean(createReqVO, FinanceMonadDO.class);
        financeMonadMapper.insert(financeMonad);

        // 返回
        return financeMonad.getId();
    }

    @Override
    public void updateFinanceMonad(FinanceMonadSaveReqVO updateReqVO) {
        // 校验存在
        validateFinanceMonadExists(updateReqVO.getId());
        // 更新
        FinanceMonadDO updateObj = BeanUtils.toBean(updateReqVO, FinanceMonadDO.class);
        financeMonadMapper.updateById(updateObj);
    }

    @Override
    public void deleteFinanceMonad(Integer id) {
        // 校验存在
        validateFinanceMonadExists(id);
        // 删除
        financeMonadMapper.deleteById(id);
    }

    @Override
        public void deleteFinanceMonadListByIds(List<Integer> ids) {
        // 删除
        financeMonadMapper.deleteByIds(ids);
        }


    private void validateFinanceMonadExists(Integer id) {
        if (financeMonadMapper.selectById(id) == null) {
            throw exception(FINANCE_MONAD_NOT_EXISTS);
        }
    }

    @Override
    public FinanceMonadDO getFinanceMonad(Integer id) {
        return financeMonadMapper.selectById(id);
    }

    @Override
    public PageResult<FinanceMonadDO> getFinanceMonadPage(FinanceMonadPageReqVO pageReqVO) {
        return financeMonadMapper.selectPage(pageReqVO);
    }

}